package com.ai.controller.made;

import com.ai.annotation.EnterPathParamLog;
import com.ai.common.CommonResponse;
import com.ai.common.vaild.AddGroup;
import com.ai.common.vaild.UpdateGroup;
import com.ai.entity.server.ServerBO;
import com.ai.entity.server.ServerPage;
import com.ai.service.made.ServerService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 *  服务器
 * @author Mr.Chen
 * @since 2020-06-17
 */
@RestController
@RequestMapping("/server")
@Slf4j
public class ServerController {


    @Autowired
    ServerService serverService;

    /**
     * 通过ID查询
     *
     * @param serverBO
     * @return
     */
    @ApiOperation("通过ID查询")
    @PostMapping("oneById")
    @EnterPathParamLog
    public CommonResponse oneById(@RequestBody ServerBO serverBO) {
        CommonResponse resultData = serverService.oneById(serverBO);
        log.info(resultData.toString());
        return resultData;
    }


    /**
     * 修改信息
     *
     * @param serverBO
     * @return
     */
    @ApiOperation("修改信息")
    @PostMapping("modifyInfo")
    @EnterPathParamLog
    public CommonResponse modifyInfo(@RequestBody @Validated({UpdateGroup.class}) ServerBO serverBO) {
        CommonResponse resultData = serverService.modifyInfo(serverBO);
        log.info(resultData.toString());
        return resultData;
    }


    /**
     * 添加
     *
     * @param serverBO
     * @return
     */
    @ApiOperation("添加")
    @PostMapping("add")
    @EnterPathParamLog
    public CommonResponse add(@RequestBody @Validated({AddGroup.class})  ServerBO serverBO) {
        CommonResponse resultData = serverService.insert(serverBO);
        log.info(resultData.toString());
        return resultData;
    }

    /**
     * 删除
     *
     * @param serverBO
     * @return
     */
    @ApiOperation("删除")
    @PostMapping("delete")
    @EnterPathParamLog
    public CommonResponse delete(@RequestBody ServerBO serverBO) {
        CommonResponse resultData = serverService.delete(serverBO);
        log.info(resultData.toString());
        return resultData;
    }

    /**
     * 分页查询，列表查询
     *
     * @param page
     * @return
     */
    @ApiOperation("分页查询")
    @PostMapping("list")
    @EnterPathParamLog
    public CommonResponse selectByPage(@RequestBody ServerPage page) {
        CommonResponse resultData = serverService.selectByPage(page);
        log.info(resultData.toString());
        return resultData;
    }

    /**
     * 查询打开的服务器
     *
     * @return
     */
    @ApiOperation("查询打开的服务器")
    @GetMapping("listByOpen")
    @EnterPathParamLog
    public CommonResponse listByOpen() {
        CommonResponse resultData = serverService.listByOpen();
        log.info(resultData.toString());
        return resultData;
    }
}